package com.ll.app.controller;

import com.ll.app.api.req.AddShopReqDTO;
import com.ll.app.api.yhj.AddUploadFileReqDTO;
import com.ll.app.api.yhj.PageFileReqDTO;
import com.ll.base.dto.ApiResultDTO;
import com.ll.base.dto.PageReqDTO;
import com.ll.domain.shop.biz.ShopDomainService;
import com.ll.domain.yhj.biz.YhjDomainService;
import com.ll.domain.yhj.enums.FileTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/yhj/api")
@RequiredArgsConstructor
@Api(tags = "银伙计相关API")
public class YhjController {

    private final YhjDomainService yhjDomainService;

    @ResponseBody
    @ApiOperation(value = "文件列表")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public ApiResultDTO page(@RequestBody @Validated PageFileReqDTO pageReq) {
        return ApiResultDTO.success(yhjDomainService.pageFile(pageReq));
    }


    @ResponseBody
    @ApiOperation(value = "添加文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型", example = "音乐", required = true),
            @ApiImplicitParam(name = "name", value = "名称", example = "听雨", required = true),
    })
    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    public ApiResultDTO uploadFile(
            @RequestParam( "type") FileTypeEnum type,
            @RequestParam("name") String name,
            @RequestParam("file") MultipartFile file) {

        AddUploadFileReqDTO reqDTO = AddUploadFileReqDTO.builder()
                .name(name)
                .type(type)
                .build();
        return yhjDomainService.addFile(reqDTO, file);
    }
}


